package com.atguigu.gmall.product.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 带有inner的url表示提供给内部的微服务调用
 *
 * @author Fxz
 * @version 1.0
 * @date 2022-02-07 17:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/product")
public class ProductApiController {

	private final ManageService manageService;

	/**
	 * 跟据skuId返回skuInfo
	 */
	@GetMapping("/inner/getSkuInfo/{skuId}")
	public SkuInfo getSkuInfo(@PathVariable Long skuId) {
		return manageService.getSkuInfo(skuId);
	}

	/**
	 * 跟据三级分类id获取分类信息
	 */
	@GetMapping("/inner/getCategoryView/{category3Id}")
	public BaseCategoryView getCategoryView(@PathVariable Long category3Id) {
		return manageService.getCategoryViewByCategory3Id(category3Id);
	}

	/**
	 * 跟据skuId获取商品价格
	 */
	@GetMapping("/inner/getSkuPrice/{skuId}")
	public BigDecimal getSkuPrice(@PathVariable Long skuId) {
		return manageService.getSkuPrice(skuId);
	}

	/**
	 * 跟据spuId和skuId查询销售属性和销售属性值
	 */
	@GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
	public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable long skuId, @PathVariable long spuId) {
		return manageService.getSpuSaleAttrListCheckBySku(spuId, skuId);
	}

	/**
	 * 跟据spuId获取skuId和销售属性id的组合
	 */
	@GetMapping("/inner/getSkuValueIdsMap/{spuId}")
	public Map<Object, Object> getSkuValueIdsMap(@PathVariable Long spuId) {
		return manageService.getSkuValueIdsMap(spuId);
	}

	/**
	 * 获取所有分类数据集合
	 */
	@GetMapping("/getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList() {
		return Result.ok(manageService.getBaseCategoryList());
	}

	/**
	 * 跟据品牌id获取品牌数据
	 */
	@GetMapping("/inner/getTrademark/{tmId}")
	public BaseTrademark getTrademark(@PathVariable Long tmId) {
		return manageService.getTrademark(tmId);
	}

	/**
	 * 跟据skuId获取平台属性、平台属性值
	 */
	@GetMapping("/inner/getAttrList/{skuId}")
	public List<BaseAttrInfo> getAttrList(@PathVariable Long skuId) {
		return manageService.getAttrList(skuId);
	}

}
